﻿namespace EasyWeb.Extensions
{
    using System;
    using System.ComponentModel.Composition.Hosting;

    public static class EWExtensionManager
    {
        public static CompositionContainer CompositionContainer { get; private set; }

        public static Func<CompositionContainer> DefaultFactory
        {
            get { return CreateDefaultCompositionContainer; }
        }

        public static void Initialize(Func<CompositionContainer> factory)
        {
            factory = factory == null ? DefaultFactory : factory;
            CompositionContainer = factory();
        }

        private static CompositionContainer CreateDefaultCompositionContainer()
        {
            var directory = EWHelpers.Environment.MapPath("~/bin");
            var directoryCatalog = new DirectoryCatalog(directory);

            return new CompositionContainer(directoryCatalog);
        }
    }
}
